import arcpy
import os
import sys
import subprocess

from accumulatetonetwork import AccumulateToNetworkTool
from polylinerasterintersect import PolylineRasterIntersectTool
import stormwaterutilities

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Stormwater Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox
        self.tools = [AccumulateToNetworkTool, PolylineRasterIntersectTool]

class Test(object):
    def __init__(self):
        """Tester."""
        self.label = "Test"
        self.description = "Tester"
        self.canRunInBackground = True

    def getParameterInfo(self):
        """Define parameter definitions"""
        param0 = arcpy.Parameter(
            displayName="Conveyance Lines Feature Class",
            name="lines_fc",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        param0.filter.list = ['LINE']

        param1 = arcpy.Parameter(
            displayName="Conveyance Nodes Feature Class",
            name="nodes_fc",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input")

        param1.filter.list = ['POINT']

        param2 = arcpy.Parameter(
            displayName="Conversion Factor",
            name="factor",
            datatype="GPDouble",
            direction="Input")

        params = [param0, param1, param2]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        arcpy.AddMessage("Testing the exe launcher")

        args = ["Test"]

        for p in parameters:
            arcpy.AddMessage(p.name + ": " + p.datatype + " " + p.valueAsText)
            if p.datatype in ["Feature Layer", "GPRasterLayer"]:
                desc = arcpy.Describe(p.valueAsText)
                arcpy.AddMessage(desc.catalogPath)
                args.append(desc.catalogPath)
            else:
                args.append(p.valueAsText)

        arcpy.AddMessage(str(args))
        helper = Helper()
        helper.CallExe([args])
        return
